package com.youxuit.youxu.kecheng.SynchronizedDemo;


//方法锁
public class SyncronizedMethodBlock3 implements Runnable{

    public static SyncronizedMethodBlock3 block2 = new SyncronizedMethodBlock3();

    @Override
    public void run() {
        methord();
    }

    private synchronized  void methord(){
        System.out.println("我的线程名字是：" + Thread.currentThread().getName() + ",我开始运行了");

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {

        }
        System.out.println("我的线程名字是：" + Thread.currentThread().getName() + "，运行结束了");
    }

    public static void main(String[] args) {
        Thread t1 = new Thread(block2);
        Thread t2 = new Thread(block2);
        t1.start();
        t2.start();

        while (t1.isAlive() || t2.isAlive()) {

        }
        System.out.println("finish");
    }
}
